<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:replace="~{common::header('采购计划一览表')}"></head>
<body>
<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-12 column" style="text-align: center">
            <h3>
                采购计划一览表
            </h3>
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-12 column">
            <hr>
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="col-sm-6 col-md-3 column form-inline">
                <label for="a1">产品编码:</label>
                <input type="text" class="form-control" id="a1" placeholder="产品编码">
            </div>
            <div class="col-sm-6 col-md-3 column form-inline">
                <label for="a2">产品名称:</label>
                <input type="text" class="form-control" id="a2" placeholder="产品名称">
            </div>

            <div class="col-sm-6 col-md-2 column form-inline">
                <label for="a3">计划状态:</label>
                <select class="form-control" id="a3">
                    <option>全部</option>
                    <option value="C001-30">未确定</option>
                    <option value="C001-40">待审</option>
                    <option value="C001-50">通过</option>
                    <option value="C001-51">不通过</option>
                    <option value="C001-60">下达</option>
                </select>
            </div>

            <div class="col-sm-6 col-md-2 column form-inline">
                <label for="a4">采购类型:</label>
                <select class="form-control" id="a4">
                    <option>全部</option>
                    <option value="C000-1">公开求购</option>
                    <option value="C000-2">定向询价</option>
                </select>
            </div>

            <div class="col-sm-12 col-md-2 column">
                <button type="button" class="btn btn-primary" onclick="btn1()" style="margin-right: 10px">搜索</button>
                <button type="button" class="btn btn-primary" onclick="btn2()" >重置</button>
            </div>

        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-12 column">
            <hr>
        </div>
    </div>
    <div class="row clearfix" style="max-height: 50%;overflow-y: auto;overflow-x: hidden">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div class="col-md-12 column" style="overflow: hidden">
                    <table id="dg" class="easyui-datagrid"
                           data-options="
								  	pageSize:'10',
								  	pageList:[10,20,30,40],
									pagination:true,
									rownumbers:true,
									singleSelect:true,
									url:'/stock/selectStock',
									method:'post',
									width:'100%'">
                        <thead>
                        <tr>
                            <th data-options="field:'ck',checkbox: true"></th>
                            <th data-options="field:'id'" hidden>Item ID(15%)</th>
                            <th data-options="field:'stock_name',width:'24%'">采购计划名称</th>
                            <th data-options="field:'stock_type',width:'24%',formatter: function(value,row,index){
                                                                                    if(value=='C000-1'){
                                                                                        return '制造中心采购-公开求购';
                                                                                    }else{
                                                                                        return '制造中心采购-定向询价';
                                                                                    }} ">采购类型</th>
                            <th data-options="field:'status',width:'24%',formatter: function(value,row,index){
                                                                                    if(value=='C001-30'){
                                                                                        return '未确定';
                                                                                    }else if(value=='C001-40'){
                                                                                        return '待审';
                                                                                    }else if(value=='C001-50'){
                                                                                        return '通过';
                                                                                    }else if(value=='C001-51'){
                                                                                        return '不通过';
                                                                                    }else if(value=='C001-60'){
                                                                                        return '下达';
                                                                                    }}">计划状态</th>
                            <th data-options="field:'submit_date',width:'24%'">下达时间</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>


    <div class="row clearfix">
        <div class="col-md-12 column">
            <hr>
        </div>
    </div>

    <div class="col-md-12 column">
        <div class="col-md-12 column" style="padding-top:10px;text-align:center">
            <button type="button" onclick="btn3()"  class="btn btn-primary" >报批</button>
            <button type="button" onclick="btn4()"  class="btn btn-primary" >详情</button>
        </div>
    </div>

</div>


<script>

    //模糊查询
    var btn1=function (){
        var a1=$("#a1").val();
        var a2=$("#a2").val();
        var a3=$("#a3").val();
        var a4=$("#a4").val();
        $('#dg').datagrid({
            url:'/stock/selectStock',
            method:'post',
            queryParams: {
                stockName:a1,
                materialName:a2,
                status:a3,
                stockType:a4,
            }
        });
    }

    //重置搜索数据
    var btn2=function(){
        $("#a1").val("");
        $("#a2").val("");
        $("#a3").val("全部");
        $("#a4").val("全部");
    }

    var btn3=function(){
       var row= $("#dg").datagrid("getSelected");
       if (row!=null){
            if (row.status=='C001-30'){
                $.ajax({
                    url: "/idMapping/updatebyStatusByStock?StockId="+row.id,
                    method: "get",
                    success:function (){
                        $('#dg').datagrid('reload');
                    }
                });
            }
       }
    }

    var btn4=function(){
        var rows= $("#dg").datagrid("getSelections");
        if (rows.length!=0){
            for (var i = 0; i < rows.length; i++) {
                URL1="/stock/findbyID?ID="+rows[i].id;
                open(URL1,"","");
            }
        }
    }
</script>


</body>

</html>